
package simuri.uridb;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author fomy
 */
public class ComputeCohUris {
    
 public int DIRECT_EDGE_FACTOR = 10;
 Connection con = DbConnection.getConnection(); 
    
 public void CohInDb(String allcohfile) {
         
    try{
       
       BufferedReader br = new BufferedReader(new FileReader(allcohfile));
        DbLookUp dlp = new DbLookUp();
        Statement stmt = con.createStatement();
        
        Set<String> set = new HashSet<>();
        String line,ins;
        int number = 0;
        String sql = "SELECT distinct uriname FROM words_uris";
        java.sql.ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            number++;
            String  resource = rset.getString("uriname");
            set.add(resource);
        }
         
        while ((line = br.readLine()) != null){
        System.out.println(line);
        String[]split= line.split("\t");
        String uriname1 = "http://dbpedia.org/resource/"+split[0];
        String uriname2 = "http://dbpedia.org/resource/"+split[1];
        int coh = Integer.parseInt(split[2]);
        System.out.println(uriname1 +"----"+uriname2);
        
        if( set.contains(uriname1) && set.contains(uriname2)){    
        ins = "INSERT INTO uricoherence (uri1,uri2,weight) VALUES(" + uriname1 + "," + uriname2 + "," + coh + ")";
        stmt.execute(ins);
        }
       }

      stmt.close();
       con.close();
    } catch (SQLException | IOException | NumberFormatException se) {
    System.out.println("SQL Fehler " + se.getMessage());
    se.printStackTrace(System.out);
}
    }

}
